package model;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import model.AbstractBullet;

/**
 * This class represents the smurf the players control
 * 
 * @author Niklas
 *
 */

public class Smurf {
	
	private String name;
	private double x;
	private double y;
	private double xSpeed;
	private double ySpeed;
	private Dimension size = new Dimension(32,48);
	private BufferedImage image = null;
	private Sprite sprite;
	private List<AbstractBullet> bullets = new ArrayList<AbstractBullet>();
	
	/**
	 * 
	 * @param name - the player name
	 */
	public Smurf(String name){
		this(name, 0, 0, 0, 0);
	}
	
	/**
	 * @param name Players name
	 * @param x x-coordinate
	 * @param y y-coordinate
	 */
	public Smurf(String name, double x, double y, double xSpeed, double ySpeed){
		this.name = name;
		setX(x);
		setY(y);
		setXSpeed(xSpeed);
		setYSpeed(ySpeed);
		sprite = new Sprite("sprites//smurf//stand");
	}
	
	/**
	 * @return dimension of smurf
	 */
	public Dimension getSize(){
		return size;
	}
	
	/**
	 * @param image The image to be set at the Smurf's image
	 */
	public void setImage(BufferedImage image){
		this.image = image;
	}
	
	/**
	 * Getting the Smurf's image
	 * @return the Smurf's image
	 */
	public BufferedImage getImage(){
		return image;
	}
	
	/**
	 * @return the x position
	 */
	public double getX() {
		return x;
	}
	/**
	 * @return the y position
	 */
	public double getY() {
		return y;
	}
	
	/**
	 * 
	 * @return name - the player name
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * @param x the x to set
	 */
	public void setX(double x) {
		this.x = x;
	}


	/**
	 * @param y the y to set
	 */
	public void setY(double y) {
		this.y = y;
	}


	/**
	 * @return the xSpeed - the speed of the smurf horizontally
	 */
	public double getXSpeed() {
		return xSpeed;
	}

	/**
	 * @param xSpeed - the xSpeed to set
	 */
	public void setXSpeed(double xSpeed) {
		this.xSpeed = xSpeed;
	}

	/**
	 * @return the ySpeed
	 */
	public double getYSpeed() {
		return ySpeed;
	}
	
	/**
	 * @param ySpeed - the ySpeed to set
	 */
	public void setYSpeed(double ySpeed) {
		this.ySpeed = ySpeed;
	}
	
	/**
	 * @param speed - the speed to add to the xSpeed
	 */
	public void addXSpeed(Double xSpeed) {
		this.xSpeed = this.xSpeed + xSpeed;
	}

	/**
	 * @return speed - the speed to add to the ySpeed
	 */
	public double addYSpeed(Double ySpeed) {
		return this.ySpeed = this.ySpeed + ySpeed;
	}
	
	/**
	 * Sets the list of bullets belonging to the smurf
	 * @param bullets
	 */
	public void setBullets(List<AbstractBullet> bullets){
		this.bullets = bullets; 
	}
	
	/**
	 * @return The list of bullets belonging to the smurf
	 */
	public List<AbstractBullet> getBullets(){
		return bullets;
	}

	/**
	 * Adds a bullet to the bulletlist
	 * @param bullet
	 */
	public void addBullet(AbstractBullet bullet){
		bullets.add(bullet);
	}
	
	/**
	 * Removes a bullet from the bulletlist, ex when it has hit
	 * @param bullet
	 */
	public void removeBullet(AbstractBullet bullet){
		bullets.remove(bullet);
	}
	
	/**
	 * tests collisions between smurfs
	 * @param smurf - another smurf
	 */
	public boolean hitTest(Smurf smurf){
		//TODO make a collision method
		return true;
	}
	
	public void draw(Graphics g) {
		g.setColor(Color.red);
		//g.fillRect((int)(x + 0.5), (int)(y + 0.5 - size.height), size.width, size.height);
		//weapon.draw(g,(int)( x + size.width - 0.5),(int)(y + size.height/2 + 0.5));
		sprite.draw((int)x,(int)y-size.height,g);
	}

}
